import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'
const RolesKey = 'Admin-Roles'
const UserinfoKey = 'Admin-Userinfo'

export function getToken() {
	return Cookies.get(TokenKey)
}

export function setToken(token) {
	return Cookies.set(TokenKey, token)
}

export function removeToken() {
	return Cookies.remove(TokenKey)
}

export function getRoles() {
	return Cookies.get(RolesKey) ? JSON.parse(Cookies.get(RolesKey)) : []
}

export function setRoles(roles = []) {
	return Cookies.set(RolesKey, JSON.stringify(roles))
}

export function removeRoles() {
	return Cookies.remove(RolesKey)
}

export function getUserInfo() {
	return Cookies.get(UserinfoKey) ? JSON.parse(Cookies.get(UserinfoKey)) : {}
}

export function setUserInfo(userInfo = {}) {
	return Cookies.set(UserinfoKey, JSON.stringify(userInfo))
}

export function removeUserInfo() {
	return Cookies.remove(UserinfoKey)
}
